Skip to content

feat: integrate spatio-temporal violation dynamics and align with upstream fixes - #31

Open
HaoLi111 wants to merge 7 commits into
openclaw:mainfrom
HaoLi111:feature/spatio-temporal-dynamics-v2
Open

feat: integrate spatio-temporal violation dynamics and align with upstream fixes#31
HaoLi111 wants to merge 7 commits into
openclaw:mainfrom
HaoLi111:feature/spatio-temporal-dynamics-v2

Conversation

@HaoLi111

@HaoLi111 HaoLi111 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

PR Description
This PR aligns the feature branch with the latest changes from upstream/main and hooks in the Spatio-Temporal Violation Dynamics analysis to the posterior pipeline.

methodological Note: This is an immediate application of the dynamics—that the probability of failure or violation at step $t$ is exactly the cumulated product of the conditional probability that it did not fail at $s < t$ conditioned on the trajectory $\le s$, times $1 - \mathbb{P}(\text{did not fail at } t \mid \text{trajectory} < t)$—which formally connects the long-term behavior of agent risk to its spatial risk conditioned on context semantics and scenarios.

i.e.

$$ \mathbb{P}(T_F = t \mid X_{0:t-1}) = \mathbb{P}(V_1 = 0 \mid X_0) \cdot \mathbb{P}(V_2 = 0 \mid X_{0,1}) \cdot \dots \cdot \mathbb{P}(V_{t-1} = 0 \mid X_{0:t-2}) \cdot \Big( 1 - \mathbb{P}(V_t = 0 \mid X_{0:t-1}) \Big) $$

which let you do a lot of things.

Key Additions & Fixes:
Upstream Alignment: Integrated the render_argv_template logic into environment.py and environment_files.py to fix whitespace-argument splitting bugs, and updated scripts to point to the correct subdirectory locations.
Violation Time Decomposition: Hooked violation_time_decomposition.py into the main pipeline. It now writes session results (violation_metrics.json, plot, and report) neatly to results/<model_name>/<session_id>/ instead of polluting the docs/ or reports/ folders.
Test Suite Stability: Created tests/conftest.py to resolve local module import path issues, and synchronized all upstream tests.

Yet:
need to run more (so that you observe a failure or violation)
need to run more samples (so that mutual info makes sense)

Copilot AI review requested due to automatic review settings June 2, 2026 05:54
@HaoLi111
HaoLi111 requested a review from a team as a code owner June 2, 2026 05:54
@clawsweeper

clawsweeper Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed August 5, 2026, 8:08 AM ET / 12:08 UTC.

ClawSweeper review

What this changes

The PR adds a turn-level violation-time decomposition report to ShellBench’s posterior-dynamics pipeline, plus metadata handling and focused tests.

Merge readiness

Blocked until real behavior proof is added - 5 items remain

Keep open: the feature is not on current main, but the unchanged branch still misattributes unlocalized violations and keeps censored runs at risk beyond their final observed turn. It also lacks the promised real archive-output proof; member involvement on the branch means stale-proof auto-close does not apply.

Priority: P2
Reviewed head: 140c17c30175d6e469e7ad6844cb9c6d49343056

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The analytical direction is useful, but two correctness blockers and absent real-run proof leave this PR unready to merge.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR body says more runs are needed and provides no after-fix archive output, report artifact, or redacted terminal/log evidence; add a run with an observed violation and its generated metrics, redacting private data, then update the PR body for re-review.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body says more runs are needed and provides no after-fix archive output, report artifact, or redacted terminal/log evidence; add a run with an observed violation and its generated metrics, redacting private data, then update the PR body for re-review.
Evidence reviewed 5 items Current main does not contain the proposed analysis: The current posterior pipeline runs constraint, regime, variance, survival, and ranking analyses, then generates its report; it has no violation-time stage.
Unlocalized violations are assigned a false turn: Trajectory violations can be caused by forbidden tools and configured shell patterns, but the PR only finds dangerous shell commands; other violations fall through to the final assistant turn as an event.
Existing survival convention censors at the last observed turn: Current main returns the final assistant turn for a non-event, whereas this PR returns one turn after it; its at-risk calculation then includes an unobserved turn.
Findings 2 actionable findings [P2] Keep unlocalized violations out of turn-specific metrics
[P2] Censor nonviolating runs at their final observed turn
Security None None.

How this fits together

ShellBench reads archived agent trajectories through its posterior-dynamics pipeline and writes benchmark reports. This PR adds a safety-violation timing analysis that consumes trajectory violations and emits per-model metrics, plots, and Markdown reports.

flowchart LR
  A[Archived benchmark runs] --> B[Posterior dynamics pipeline]
  B --> C[Violation-time analysis]
  C --> D[Per-model metrics and plot]
  D --> E[Benchmark report artifacts]
  B --> F[Existing survival analysis]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body says more runs are needed and provides no after-fix archive output, report artifact, or redacted terminal/log evidence; add a run with an observed violation and its generated metrics, redacting private data, then update the PR body for re-review.
  • Keep unlocalized violations out of turn-specific metrics (P2) - forbidden_violations also records forbidden tools and configured shell patterns, but this scan recognizes only dangerous shell commands. The fallback therefore turns an unlocalized violation into an event at the final assistant turn, biasing hazards and mutual information; preserve unknown timing or localize all supported violation types.
  • Censor nonviolating runs at their final observed turn (P2) - A one-turn non-event returns (2, False), and tf >= t keeps it in the risk set at unobserved turn two. Return the final observed assistant turn for censoring, consistent with the existing survival analysis, and add a regression test for the resulting hazard denominator.
  • Resolve merge risk (P1) - Merging before the timing and censoring repairs would publish misleading violation hazards and mutual-information metrics from benchmark runs.
  • Complete next step (P2) - The two statistical defects have narrow, source-proven repairs; contributor-supplied real behavior proof remains required afterward.

Findings

  • [P2] Keep unlocalized violations out of turn-specific metrics — scripts/violation_time_decomposition.py:31
  • [P2] Censor nonviolating runs at their final observed turn — scripts/violation_time_decomposition.py:23-24
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Implementation and test delta production +242/-4, tests +35 The new 215-line analysis script materially expands the reporting pipeline while its test file currently covers only two narrow input cases.

Merge-risk options

Maintainer options:

  1. Repair event timing before merge (recommended)
    Keep unlocalized violations out of turn-specific estimates, censor non-events at their final observed turn, and cover both cases with regression tests before reviewing real-run evidence.
  2. Pause the new analysis
    Do not merge the violation-time stage if its event-time semantics cannot be made explicit and validated against a real archive.

Technical review

Best possible solution:

Preserve unknown violation timing instead of fabricating a final-turn event, censor non-events at their final observed turn, add regression coverage, and then demonstrate the completed pipeline on a redacted real archive containing an observed violation.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: a run with a forbidden non-dangerous tool or shell-pattern violation reaches the fallback event time, and a one-turn nonviolating run is kept at risk at turn two. These focused cases are not yet covered by the PR’s tests.

Is this the best way to solve the issue?

No; integrating the analysis is consistent with the existing posterior pipeline, but assigning unknown violations to a final turn and censoring beyond observed data is not a valid implementation of the intended statistics.

Full review comments:

  • [P2] Keep unlocalized violations out of turn-specific metrics — scripts/violation_time_decomposition.py:31
    forbidden_violations also records forbidden tools and configured shell patterns, but this scan recognizes only dangerous shell commands. The fallback therefore turns an unlocalized violation into an event at the final assistant turn, biasing hazards and mutual information; preserve unknown timing or localize all supported violation types.
    Confidence: 0.99
  • [P2] Censor nonviolating runs at their final observed turn — scripts/violation_time_decomposition.py:23-24
    A one-turn non-event returns (2, False), and tf >= t keeps it in the risk set at unobserved turn two. Return the final observed assistant turn for censoring, consistent with the existing survival analysis, and add a regression test for the resulting hazard denominator.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: not found in the target repository.

Codex review notes: model internal, reasoning high; reviewed against 884dd1bb5511.

Labels

Label justifications:

  • P2: The PR adds a bounded benchmark-analysis capability, but incorrect timing and censoring can affect reported reliability metrics.
  • merge-risk: 🚨 other: The merge can produce analytically incorrect benchmark safety reports even though it does not fit a more specific delivery, compatibility, or security risk class.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body says more runs are needed and provides no after-fix archive output, report artifact, or redacted terminal/log evidence; add a run with an observed violation and its generated metrics, redacting private data, then update the PR body for re-review.

Evidence

Acceptance criteria:

  • [P1] pytest tests/test_violation_time_decomposition.py tests/test_dynamics.py.
  • [P1] Run the posterior-dynamics pipeline on a redacted archive containing an observed violation and inspect the generated violation metrics/report.

What I checked:

  • Current main does not contain the proposed analysis: The current posterior pipeline runs constraint, regime, variance, survival, and ranking analyses, then generates its report; it has no violation-time stage. (scripts/run_posterior_dynamics_pipeline.py:87, 884dd1bb5511)
  • Unlocalized violations are assigned a false turn: Trajectory violations can be caused by forbidden tools and configured shell patterns, but the PR only finds dangerous shell commands; other violations fall through to the final assistant turn as an event. (scripts/violation_time_decomposition.py:31, 140c17c30175)
  • Existing survival convention censors at the last observed turn: Current main returns the final assistant turn for a non-event, whereas this PR returns one turn after it; its at-risk calculation then includes an unobserved turn. (scripts/survival_analysis.py:49, 884dd1bb5511)
  • The prior blockers remain on the same reviewed head: The latest completed review identified both timing and censoring defects; the relevant files have no changes between that reviewed SHA and the current PR head. (scripts/violation_time_decomposition.py:23, 140c17c30175)
  • Feature-history routing: Current main’s posterior-dynamics driver dates to Hao’s spatio-temporal dynamics commit, while the survival-analysis implementation and its censoring semantics date to Vincent Koc’s base implementation. (scripts/run_posterior_dynamics_pipeline.py:87, 5c58e7beaaa5)

Likely related people:

  • Hao: Introduced the current main posterior-dynamics pipeline that this PR extends. (role: current pipeline contributor; confidence: high; commits: 5c58e7beaaa5; files: scripts/run_posterior_dynamics_pipeline.py)
  • Vincent Koc: Current survival-analysis timing and censoring behavior is attributed to this implementation in blame history. (role: original survival-analysis contributor; confidence: high; commits: fc86dd615523; files: scripts/survival_analysis.py)
  • scoootscooob: A repository member reviewed the PR and authored its two latest repair commits. (role: reviewer and branch repair contributor; confidence: high; commits: 27412cf05397, 140c17c30175; files: scripts/violation_time_decomposition.py, pyproject.toml)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Repair unknown-violation attribution and censoring, with focused regression tests.
  • Attach redacted output from a real archive run that includes an observed violation and the generated report artifacts.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (32 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-03T19:02:45.721Z sha 140c17c :: needs real behavior proof before merge. :: [P2] Preserve unknown timing for unlocalized violations
  • reviewed 2026-08-03T20:13:35.157Z sha 140c17c :: needs real behavior proof before merge. :: [P2] Preserve unknown timing for unlocalized violations
  • reviewed 2026-08-04T15:04:05.789Z sha 140c17c :: needs real behavior proof before merge. :: [P2] Preserve unknown timing for unlocalized violations
  • reviewed 2026-08-04T18:03:39.598Z sha 140c17c :: needs real behavior proof before merge. :: [P2] Keep unlocalized violations out of turn-specific metrics
  • reviewed 2026-08-04T21:04:43.802Z sha 140c17c :: needs real behavior proof before merge. :: [P2] Preserve unknown timing for unlocalized violations
  • reviewed 2026-08-04T23:03:11.138Z sha 140c17c :: needs real behavior proof before merge. :: [P2] Preserve unknown timing for unlocalized violations | [P2] Censor runs at their last observed turn
  • reviewed 2026-08-05T00:18:54.723Z sha 140c17c :: needs real behavior proof before merge. :: [P2] Preserve unknown timing for unlocalized violations | [P2] Censor runs at their last observed turn
  • reviewed 2026-08-05T08:36:35.767Z sha 140c17c :: needs real behavior proof before merge. :: [P2] Preserve unknown timing for unlocalized violations | [P2] Censor nonviolating runs at their final observed turn

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR expands ClawBench’s evaluation/dynamics tooling by adding “perturbed” task variants, posterior reweighting + reporting scripts, and improving execution-check command rendering so templated values containing whitespace remain a single argv element.

Changes:

  • Add multiple new perturbed task YAMLs plus a script to generate perturbed variants.
  • Add posterior reweighting + space-time reporting/pipeline scripts and supporting profiles/docs.
  • Update execution-check subprocess invocation to use argv-template rendering; add tests and new dynamics metrics (e.g., Rényi proxy).

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/test_trajectory.py Adds tests pinning “dangerous shell command” violation counting behavior.
tests/test_environment_files.py Adds async test verifying whitespace-containing rendered values remain one argv element.
tests/test_environment.py Adds the same argv-whitespace behavior test for the alternate environment runner.
tests/conftest.py Forces repo-root importability in pytest by inserting into sys.path.
tasks-public/tier3/t3-web-research-and-cite-perturbed.yaml Adds a new perturbed Tier 3 task definition.
tasks-public/tier3/t3-msg-inbox-triage-perturbed.yaml Adds a new perturbed Tier 3 task definition.
tasks-public/tier3/t3-feature-export-perturbed.yaml Adds a new perturbed Tier 3 task definition.
tasks-public/tier3/t3-data-sql-query-perturbed.yaml Adds a new perturbed Tier 3 task definition.
tasks-public/tier3/t3-data-pipeline-report-perturbed.yaml Adds a new perturbed Tier 3 task definition.
tasks-public/tier1/t1-fs-quick-note-perturbed.yaml Adds a new perturbed Tier 1 task definition.
tasks-public/tier1/t1-bugfix-discount-perturbed.yaml Adds a new perturbed Tier 1 task definition.
scripts/violation_time_decomposition.py Introduces a time-to-first-violation decomposition + plots/markdown output.
scripts/run_posterior_reweighting.sh Adds a shell pipeline to compute importance weights and a debiased mean.
scripts/run_posterior_dynamics_pipeline.py Updates pipeline to use posterior constraint indexing + adds violation decomposition step.
scripts/run_eval_pipeline.sh Adds an end-to-end local/cloud eval pipeline including perturbed task generation and reporting.
scripts/posterior/3_generate_space_time_report.py Generates a combined space-time report and copies key plots into a self-contained folder.
scripts/posterior/1_compute_posterior_weights.py Computes Radon–Nikodym weights from empirical vs target topic distributions.
scripts/generate_perturbed_tasks.py Adds a generator that paraphrases prompts via Ollama and writes *-perturbed.yaml files.
scripts/debiased_evaluation.py Adds Hajek/IPW aggregation of task scores.
scripts/compute_debiased_dynamics.py Adds IPW/Hajek debiasing over regimes and constraint index.
scripts/compute_constraint_index.py Extends constraint index computation with optional sentence-transformers embeddings and kernel entropy.
profiles/user_target_distribution.json Adds an example target distribution profile.
profiles/radon_nikodym_weights.json Adds example precomputed weights.
profiles/empirical_topic_distribution.json Adds an example empirical benchmark distribution profile.
docs/task_distribution_reweighting.md Documents stratified reweighting and its space-time fusion.
docs/semantic_spatiotemporal_dynamics.md Documents the combined semantic + temporal dynamics framework.
docs/long_term_dynamics.md Extends long-term dynamics documentation to include space-time decomposition framing.
clawbench/render.py Adds render_argv_template() using shlex.split() pre-render to preserve whitespace in substituted values.
clawbench/environment_files.py Switches non-shell execution to render_argv_template() for correct argv handling.
clawbench/environment.py Same argv-template switch for the gateway environment runner.
clawbench/dynamics_archive.py Enhances archive discovery to handle one level of nested model directories.
clawbench/dynamics.py Adds renyi_d2 metric computation to per-trajectory dynamics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +24 to +29
- message: "Thinking...\nThinking Process:\n\n1. **Analyze the Request:**\n \
\ * **Task:** Paraphrase the provided instruction.\n * **Constraint 1:**\
\ Keep the exact same semantic meaning and intent.\n * **Constraint 2:**\
\ Change the wording slightly.\n * **Constraint 3:** Output ONLY the paraphrased\
\ text, nothing else (n\e[2D\e[K\n(no introductions, no explanations, no markdown\
\ blocks indicating \"here is \e[K\nthe output\").\n\n2. **Analyze the Original\
Comment thread tests/test_environment.py
Comment on lines +168 to +189
@pytest.mark.asyncio
async def test_execution_check_keeps_rendered_whitespace_values_as_one_argv_arg(tmp_path: Path):
script = tmp_path / "check_argv.py"
script.write_text(
"import json, sys\n"
"print(json.dumps(sys.argv[1:]))\n",
encoding="utf-8",
)

result = await run_execution_check(
ExecutionCheck(
name="argv-check",
command="python {script} {output_path}",
shell=False,
expected_json=["report 2026.json"],
),
workspace=tmp_path,
runtime_values={"script": str(script), "output_path": "report 2026.json"},
)

assert result.passed is True
assert result.reason == "OK"
Comment thread tests/conftest.py Outdated

# Add the repository root to sys.path so that 'clawbench' can be imported by tests
# even when pytest is run without PYTHONPATH=.
sys.path.insert(0, str(Path(__file__).parent.parent))
dyn_json = dyn_dir / "dynamics.json"
if dyn_json.exists():
try:
dyn_data = json.load(open(dyn_json))
Comment thread scripts/generate_perturbed_tasks.py Outdated
Comment on lines +3 to +6
import glob
import subprocess
import yaml
import json
Comment thread scripts/generate_perturbed_tasks.py Outdated

# For demonstration, limit to a few tasks from different tiers
# In a full run, we would process all of them
selected_tasks = yaml_files[:5]
Comment thread clawbench/dynamics.py
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 2, 2026
- message: Add CSV export functionality to the issue tracker in the workspace. Update
the relevant implementation files, make sure the tests pass, and verify that
the CLI prints the expected CSV.
- message: "Thinking...\nThinking Process:\n\n1. **Analyze the Request:**\n \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a part of prompt for perturbation was leaked into task.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank for the review! will fix that and rerun experiment for this one.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check others too: they have the same issue (not all of them)

@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants